<template>
    <div class="parent">
        <header class="header">
            <x-header class="headerContent" :left-options="{backText: ''}"><span class="title">公告</span></x-header>
        </header>
        <scroller lock-x  @on-scroll="onScroll" ref="scrollerEvent">
        <main class="main">
            <ul class="list">
                <li class="listItem" @click="goDetail(item)" v-for="(item, index) in datalist" :key="index">
                    <div class="top">
                        <div class="top_left">{{item.articleTitle}}</div>
                        <div class="top_right">{{item.createTime}}</div>
                    </div>
                    <div class="content">
                        <div class="content_left">{{item.remark}}</div>
                        <div class="content_right">
                            <span class="icon">{{item.icon}}></span>
                        </div>
                    </div>
                </li>
            </ul>
        </main>
        </scroller>
    </div>
</template>
<script>
import { XHeader, Scroller } from 'vux'
import API from '../../config/api_user.js'
export default {
    name: 'Notice',
    data () {
        return {
            datalist: [],
            dm: null,
            scrollTop: 0
        }
    },
    components: {
        XHeader,
        Scroller
    },
    created () {
        let data = JSON.parse(JSON.parse(sessionStorage.getItem('userInfo')).extraData)['0505'].child
        data.map((item, index) => {
            if (item.mc == '公告') {
                this.dm = item.dm
            }
        })
        let params = {
            articleTypeID: this.dm
        }
        API.getArticleList(params).then(res => {
            this.getDate(res.page)
        })
    },
    mounted () {
        this.$nextTick(() => {
            this.$refs.scrollerEvent.reset({top: 0})
        })
    },
    methods: {
        getDate (datalist) {
            const date = datalist
            date.map((item, index) => {
                // console.log(item)
                if(Date.now()-new Date(item.createTime) > 24*60*60*1000) {
                    item.createTime = item.createTime.substring(0, 10)
                } else if (Date.now()-new Date(item.createTime) < 24*60*60*1000) {
                    item.createTime = item.createTime.substring(10)
                }
            })
            this.datalist = date
        },
        goDetail (item) {
            this.$router.push({
               path: '/notice/noticeDetail',
                query: {
                    item: item,
                    mc: '公告'
                }
            })
        },
        onScroll (pos) {
            this.scrollTop = pos.top
        },
    }
}
</script>
<style scoped lang="less">
.parent{
    width: 100%;
    height: 100%;
    background: rgba(250, 250, 250, 1);
}
.header{
    width: 100%;
}
.title{
    font-size: 16px;
    font-family:ArialMT;
    color:rgba(255,255,255,1);
    letter-spacing:1px;
}
.headerContent{
    width: 100%;
    background:linear-gradient(135deg,rgba(255,199,38,1) 0%,rgba(249,151,22,1) 100%);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
.main{
    width: 100%;
    flex: 1;
    overflow:hidden;
    padding-bottom: 2.666667rem;
}
.list{
    width: 100%;
    margin-top: .266667rem;
    .listItem{
        width: 100%;
        height: 3.173333rem;
        background: #fff;
        position: relative;
        margin-bottom: .133333rem;
        padding: 0 .266667rem;
        .top{
            width: 100%;
            height: .933333rem;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            position: relative;
            .top_left{
                display: block;
                width: 6.666667rem;
                height: .666667rem;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 1;
                overflow: hidden;
                font-size:14px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(82,82,82,1);
                line-height:.666667rem;
                letter-spacing:1px;
            }
            .top_right{
                font-size:12px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(151,151,151,1);
                letter-spacing:1px;
            }
        }
        .top:after{
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            background: #cccccc;
            width: 100%;
            height: 1px;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
        }
        .content{
            width: 100%;
            height: 2.24rem;
            padding: 0 0.1rem;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            .content_left{
                width: 87%;
                height: 100%;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 3;
                overflow: hidden;
                font-size:12px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(151,151,151,1);
                letter-spacing:1px;
                padding: .2rem 0;
            }
            .content_right{
                width: 1.1rem;
                height: 0.7rem;
                display: flex;
                flex-direction: row;
                justify-content: center;
                align-items: center;
                span{
                    font-size: 20px;
                    color: #FFC726;
                }
            }
        }
    }
    .listItem:after{
        content: '';
        position: absolute;
        left: 0;
        bottom: 0;
        background: #cccccc;
        width: 100%;
        height: 1px;
        -webkit-transform: scaleY(0.5);
        transform: scaleY(0.5);
        -webkit-transform-origin: 0 0;
        transform-origin: 0 0;
    }
}
</style>
